package server;

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import replication.RegServer_Replication;
import rmi.Server;
import rmi.Server_Servant;
//import java.rmi.server.UnicastRemoteObject;
public class TecBoxServer {

	public static void main(String args[]){
		
			RegServer_Replication repl = new RegServer_Replication();
			Registry primary = repl.getRegistryPrimaryIp();
			Registry secondary = repl.getRegistrySecondaryIp();
			Server tecBoxserver = null;
			

			try{
	            
	            if (args[0].equals("Primary")) {
	            	tecBoxserver = new Server_Servant("Backup", repl);
	            	primary.rebind("TecBox_PrimaryServer", tecBoxserver);
	            	System.out.println("Successful");
	            	
	            }
	            else {
	            	tecBoxserver = new Server_Servant("Primary", repl);
	            	primary.rebind("TecBox_BackupServer", tecBoxserver);
	            }
	            System.out.println(args[0] + "Server ready ");
	        }catch(Exception e) {
	            System.out.println("Server main " + e.getMessage());
	        }
			
			
		    try{
	            if (args[0].equals("Primary")) {
	            	secondary.rebind("TecBox_PrimaryServer", tecBoxserver);
	            }
	            else {
	            	secondary.rebind("TecBox_BackupServer", tecBoxserver);
	            }
	            System.out.println(args[0] + "Server ready ");
	        }catch(Exception e) {
	            System.out.println("Server main " + e.getMessage());
	        }
	        

	}
	
}
